import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/home/index.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect:'/home'
    },
    {
      path: '/home',
      name: 'home',
      component: HomeView
    },
    {
      path: '/home/search',
      name: 'Search',
      component: () => import('../views/home/search/index.vue')
    },
    {
      path: '/home/address',
      name: 'Address',
      component: () => import('../views/home/address/index.vue')
    },
    {
      path: '/home/hotnew',
      name: 'Hotnew',
      component: () => import('../views/home/hot-new/index.vue')
    },
    {
      path: '/topic',
      name: 'topic',
      component: () => import('../views/topic/index.vue')
    },
    {
      path: '/category',
      name: 'category',
      component: () => import('../views/category/CategoryView.vue')
    },
    {
      path: '/category/goodslist',
      name: 'Goodslist',
      component: () => import('../views/category/GoodsList.vue')
    },
    {
      path: '/cart',
      name: 'Cart',
      component: () => import('../views/cart/index.vue')
    },
    {
      path: '/my',
      name: 'my',
      component: () => import('../views/my/index.vue')
    },
    {
      path: '/productdetail',
      name: 'ProductDetail',
      component: () => import('../views/productDetail/ProductDetail.vue')
    },
    {
      path: '/order',
      name: 'Order',
      component: () => import('../views/order/OrderConfirm.vue')
    }
  ],
  scrollBehavior (to, from, savedPosition) {
    // return 期望滚动到哪个的位置
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router
